package org.slg.oracleproject.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirements;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.slg.oracleproject.entity.Role;
import org.slg.oracleproject.entity.User;
import org.slg.oracleproject.entity.UserRole;
import org.slg.oracleproject.entity.dto.LoginDTO;
import org.slg.oracleproject.entity.dto.RefreshTokenDTO;
import org.slg.oracleproject.entity.vo.LoginVO;
import org.slg.oracleproject.respones.CommonResult;
import org.slg.oracleproject.service.RoleService;
import org.slg.oracleproject.service.UserRoleService;
import org.slg.oracleproject.service.UserService;
import org.slg.oracleproject.util.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/auth")
@Tag(name = "用户登录")
public class AuthController {

    @Autowired
    private UserService userService;


    @PostMapping("/login")
    @Operation(summary = "用户登录", description = "用户名密码登录，返回JWT访问令牌和刷新令牌")
    public CommonResult  login(@RequestBody LoginDTO loginDTO) {
        LoginVO loginVO = userService.userLogin(loginDTO);
        log.info("用户登录成功，返回令牌：{}", loginVO);
        return CommonResult.success(loginVO);
    }


    @PostMapping("/refresh-token")
    @Operation(summary = "刷新访问令牌", description = "使用refresh token获取新的access token")
    public CommonResult refreshToken(@RequestBody RefreshTokenDTO refreshTokenDTO) {
        return CommonResult.success(userService.refreshToken(refreshTokenDTO));
    }





}




